//
//  RNOLMoneyManagerRecordListViewController.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/13.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLMoneyManagerRecordListViewController.h"
#import "RNOLMoneyManagerListSubViewController.h"

@interface RNOLMoneyManagerRecordListViewController ()

@property (nonatomic,strong) RNOLFundsHeaderView *header;


@end


@implementation RNOLMoneyManagerRecordListViewController


- (RNOLFundsHeaderView *)header{
    if (!_header) {
        _header = [RNOLFundsHeaderView FromXIB];
        _header.frame = [self preferCoverFrame];
        _header.fundsRecordType = RNOLFundsListRecordTypeWaitIncome;
        _header.backgroundColor = kAppMainColor;
    }
    return _header;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addNavgationLeftBackButton];

    self.minYPullUp = 0;
    [self reloadData];
}

#pragma mark - 返回
- (void)backPopVCAction{
    [self.tabBarController.navigationController popViewControllerAnimated:YES];
}

/**
 控制器继承 SPCoverController
 此方法返回的是标题栏 标题
 */
- (NSString *)titleForIndex:(NSInteger)index
{
    return @[@"待收益",@"已收益",@"已回款"][index];
}


- (CGFloat)tabWidthForIndex:(NSInteger)index{
    return KWIDTH/3.0;
}

/**
 下面联动的ChildController控制器的数量
 */
- (NSInteger)numberOfControllers
{
    return 3;
}

/*
 (SPCoverProtocol)不用管什么时机去生成coverview
 */
- (UIView *)preferCoverView{
    return self.header;
}

- (CGRect)preferCoverFrame{
    return CGRectMake(0, 0, KWIDTH, kFundsListRecordHeaderHeight);
}

/**
 标题栏View 的Y值
 */
- (CGFloat)preferTabY{
    return kFundsListRecordHeaderHeight ;
}

/**
 下面联动的ChildController控制器
 */
- (UIViewController *)controllerAtIndex:(NSInteger)index
{
    RNOLMoneyManagerListSubViewController *coverController = [[RNOLMoneyManagerListSubViewController alloc] init];
    coverController.view.frame = [self preferPageFrame];
    RNOLFundsListRecordType type = (RNOLFundsListRecordType)index + 3;
    coverController.fundsType = type;
    return coverController;
}


//页面切换已在SPTabcontroller 实现
- (void)didPressTabForIndex:(NSInteger)index{
    [super didPressTabForIndex: index];
    RNOLFundsListRecordType type = (RNOLFundsListRecordType)index + 3;
    [self.header setFundsRecordType: type];
}

//横向滑动
- (void)scrollViewContentOffsetWithRatio:(CGFloat)ratio draging:(BOOL)draging{
    [super scrollViewContentOffsetWithRatio:ratio draging:draging];
    RNOLFundsListRecordType type = (RNOLFundsListRecordType)ratio + 3;
    [self.header setFundsRecordType: type];
}


@end
